import { ElMessage } from 'element-plus'
import { ListPage } from "custom/index";
import { getScriptManagePage, removeScriptManagePage } from './api'
import { addDialog, editDialog } from './dialog'
import { copyToClipboard } from '@/utils/common'

export async function copyAction({ props }) {
  const row = props.row || {}
  copyToClipboard(row.content || '')
  ElMessage.success('操作成功') 
}

const page = new ListPage('ScriptManagement');

page
  .api(getScriptManagePage)
  .useSearch()
    .addInputItem('keyword', '客户名称/客户ID/店铺ID/店铺名称')
    .end()
  .useTable()
    .useIndexColumn().end()
    .useColumn('title').label('标题').minWidth(140).end()
    .useColumn('content').label('内容').minWidth(600).end()
    .useColumn('createTime').label('发布时间').minWidth(200).end()
    .useColumn('createUserName').label('发布人').minWidth(140).end()
    .end()
  .usePagination()
    .end()
  .useAuthButton()
    .useItem('add').primary().content('添加话术').addRow(addDialog).end()
    .end()
  .useAuthColumn({ width: 180 })
    .useItem('edit').content('编辑').editRow(editDialog).end()
    .useItem('delete').content('删除').removeRow(removeScriptManagePage, row => [row.scriptManageId]).end()
    .useItem('copy').content('复制内容').action(copyAction).end()
    .end()

export default page
